﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace Billing2
{
    public partial class EnvCheck : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Response.AppendHeader("Cache-Control", "no-store");
            this.Response.AppendHeader("Cache-Control", "no-cache");
#if !DEV
            this.Response.AppendHeader("Content-Security-policy", "default-src https: data: 'unsafe-inline' 'unsafe-eval'");
#endif

            //anti CSRF
            if (!this.Page.IsPostBack)
            {
                string anti_csrf = ClsPasswordHelper.Encrypt("anti_csrf" + MyLib.Rand.RandomInt(0, int.MaxValue - 1).ToString()).Replace("=", "").Replace("/", "").Replace("+", "");
                this.request_id.Value = anti_csrf;
                this.Session["request_id"] = anti_csrf;
            }
            else
            {
                if (this.Session["request_id"] == null || this.request_id.Value != this.Session["request_id"].ToString())
                {
                    EPPLog.Logger.Error(Common.EscapeLog(String.Format("Detecterd CSRF1. RawUrl={0} request_id={1} inSession={2}", this.Request.RawUrl, this.request_id.Value, this.Session["request_id"])));
                    base.Response.Redirect("logout.aspx", true);
                    return;
                }
            }

            //lbl_culture.Text = this.Culture;
            //lbl_datetime.Text = String.Format("{0:dd-MMM-yyyy}", DateTime.Now);
            //this.Culture = ConfigurationManager.AppSettings["Culture"].ToString();
            //lbl_culture2.Text = this.Culture;
            //lbl_datetime2.Text = String.Format("{0:dd-MMM-yyyy}", DateTime.Now);  

//            string s = @"
//                <span style=""font-weight: bold; "">abc<br />
//                <span style=""font-style: italic; "">asdfasdf<br />
//                <span style=""text-decoration: underline; "">sdfsadfad<br />
//                </span></span></span><span style=""color: #ff0000; "">dddsad<br />
//                <span style=""font-family: arial, helvetica, sans-serif; "">fasdf<br />
//                </span></span><span style=""font-size: 14pt; "">fasdfasdfasd</span>
//                ";

//            string s = @"
//                a<br />
//                <span style=""color: #ff0000; "">b</span><br />
//                c<br />
//                <span style=""font-size: 18pt; font-weight: bold; color: #ff0000; "">ddddddd</span>
//                ";

//            s =  Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(s);

//            if (this.Session["SiteID"] == null)
//            {
//                base.Response.Redirect("default.aspx", true);
//            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            ViewStateUserKey = Session.SessionID;
        }
    }
}
